package com.example.demolib;

import han.tn.hanlibs_cachefile.CacheFile;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Button btnSave = (Button) findViewById(R.id.btnSaveFile);
		btnSave.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				boolean mt = CacheFile.saveFile(getApplicationContext(),
						"abc1234.txt", "han/tn/", "Trần Ngọc Hân");
				if (mt) {
					Toast.makeText(getApplicationContext(), "Success",
							Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(getApplicationContext(), "Fail",
							Toast.LENGTH_SHORT).show();
				}
			}
		});

		Button btnRead = (Button) findViewById(R.id.btnReadFile);
		btnRead.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String mc = CacheFile.readFile(getApplicationContext(),
						"abc1234.txt", "han/tn/");
				Toast.makeText(getApplicationContext(), mc, Toast.LENGTH_SHORT)
						.show();

			}
		});

		Button btnDelete = (Button) findViewById(R.id.btnDeleteFile);
		btnDelete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				boolean b = CacheFile.deleteCache(getApplicationContext(),
						"han/tn");
				Toast.makeText(getApplicationContext(), String.valueOf(b),
						Toast.LENGTH_SHORT).show();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
